import Vuex from 'vuex';
import Vue from 'vue';
import Server from '../utils/server';
import router from '../router/index';
import { getCookie,delCookieAll } from '@/utils/common';

Vue.use(Vuex);

export default new Vuex.Store({
    state: {
        loginPopup: false,  //登录模态框 默认不显示
        downloadPopup: true,
		category_list: [],
		hospital_detail: [],
		loginState: getCookie('user')?true:false, //登录状态
		user_info: {
			nick_name: getCookie('user')?JSON.parse(getCookie('user')).nick_name : '',
			head_img: getCookie('user')?JSON.parse(getCookie('user')).head_img : 'https://www.manydoctor.com/static/img/profile.jpg'
		},
    },
    mutations: {
        //登录模态框显示&隐藏
        togglePopup(state) {
            state.loginPopup = !state.loginPopup;
        },
        login(state) {
        	var user = getCookie('user');
        	if(user){
        		state.loginState = true; // 登录
        		state.user_info.nick_name = JSON.parse(getCookie('user')).nick_name;
        		state.user_info.head_img = JSON.parse(getCookie('user')).head_img || 'https://www.manydoctor.com/static/img/profile.jpg';
				router.go(0);
        	}
        },
        loginOut(state){
        	delCookieAll();
        	state.loginState = false; //退出登录
        	router.replace('/');//回到首页
        	this.commit('togglePopup');
        },
        //底部下载模态框显示&隐藏
        toggleDownloadPopup(state) {
            state.downloadPopup = !state.downloadPopup;
        },
        //所有项目类型
        getPlasticlist(state){
			Server.getPlasticlist().then(res => {
				state.category_list = res.data;
			})
        },
    },
    actions: {
        
    },
    modules: {

    }
});